<?
if(isset($var_name) && isset($var_value)){
    if($var_name!="" && $var_value!=""){
	$file=file("/etc/zaptel.conf");
	$tmp=0;
	$b_channel1=($var_name*31-30)."-".(($var_name*31-30)+14);
	$b_channel2=(($var_name*31-30)+16)."-".($var_name*31);
        $d_channel=(($var_name*31-30)+15);

	foreach($file as $i=>$ii){
	    if(preg_match("!span=$var_name!", $ii)){
		    if($var_value=="delete")
			array_splice($file, $i, 4);
		    else
			array_splice($file, $i, 4, array("span=$var_value\n","bchan=$b_channel1\n","dchan=$d_channel\n", "bchan=$b_channel2\n"));
		    $tmp=1;	    
	    }
	}
	if($tmp==0 && $var_value!="delete"){
		array_push($file, "span=$var_value\n");
		array_push($file, "bchan=$b_channel1\n");
		array_push($file, "dchan=$d_channel\n");
		array_push($file, "bchan=$b_channel2\n");
	}
	$f=@fopen("/etc/zaptel.conf", "w");
	foreach($file as $i)
	    @fwrite($f, $i);
	@fclose($f);
    }
}
//echo "alert('$var_name, $var_value')";
?>